package game.controller;

import common.controller.base.BaseController;
import common.model.po.*;
import common.model.response.base.Result;
import game.model.request.SaveMilestoneRequest;
import game.model.vo.MilestoneRequirementVo;
import game.model.vo.MilestoneUnlockVo;
import game.model.vo.SearchRecipeVo;
import game.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 前端控制器
 *
 * @author 米泽鹏
 * @since 2024-01-19 下午 05:05
 */
@Api(tags = "里程碑管理")
@RestController
@RequestMapping("/game/g-milestone")
public class GMilestoneController extends BaseController {

	@Resource
	private GMilestoneService service;
	@Resource
	private GMilestoneRequirementService requirementService;
	@Resource
	private GMilestoneUnlockService unlockService;
	@Resource
	private GItemService itemService;
	@Resource
	private GBuildingService buildingService;
	@Resource
	private GRecipeService recipeService;

	@ApiOperation(value = "查询所有里程碑", notes = "查询所有里程碑")
	@GetMapping("/readOnly/getAllMilestone")
	public Result<List<List<GMilestone>>> getAllMilestone() {
		return successWithData(service.getAllMilestone());
	}

	@ApiOperation(value = "查询所有物品", notes = "查询所有物品")
	@GetMapping("/readOnly/getAllItem")
	public Result<List<GItem>> getAllItem() {
		return successWithData(itemService.list());
	}

	@ApiOperation(value = "查询所有建筑", notes = "查询所有建筑")
	@GetMapping("/readOnly/getAllBuilding")
	public Result<List<GBuilding>> getAllBuilding() {
		return successWithData(buildingService.list());
	}

	@ApiOperation(value = "查询所有配方", notes = "查询所有配方")
	@GetMapping("/readOnly/getAllRecipe")
	public Result<List<GRecipe>> getAllRecipe() {
		return successWithData(recipeService.list());
	}

	@ApiOperation(value = "根据配方id查询配方详情", notes = "根据配方id查询配方详情")
	@GetMapping("/readOnly/getRecipeDetailById/{recipeId}")
	public Result<SearchRecipeVo> getRecipeDetailById(@ApiParam(value = "配方id", required = true) @PathVariable Long recipeId) {
		return successWithData(recipeService.getRecipeDetailById(recipeId));
	}

	@ApiOperation(value = "里程碑新增或更新", notes = "里程碑新增或更新")
	@PostMapping("/saveMilestone")
	public Result<?> saveMilestone(@ApiParam(value = "里程碑新增或更新请求", required = true) @RequestBody @Validated SaveMilestoneRequest request) {
		return service.saveMilestone(request);
	}

	@ApiOperation(value = "根据里程碑id查询所有里程碑成本项", notes = "根据里程碑id查询所有里程碑成本项")
	@GetMapping("/readOnly/getAllMilestoneRequirementByMilestoneId/{milestoneId}")
	public Result<List<GMilestoneRequirement>> getAllMilestoneRequirementByMilestoneId(@ApiParam(value = "里程碑id", required = true) @PathVariable Long milestoneId) {
		return successWithData(requirementService.lambdaQuery().eq(GMilestoneRequirement::getMilestoneId, milestoneId).list());
	}

	@ApiOperation(value = "根据里程碑id查询所有里程碑解锁项", notes = "根据里程碑id查询所有里程碑解锁项")
	@GetMapping("/readOnly/getAllMilestoneUnlockByMilestoneId/{milestoneId}")
	public Result<List<GMilestoneUnlock>> getAllMilestoneUnlockByMilestoneId(@ApiParam(value = "里程碑id", required = true) @PathVariable Long milestoneId) {
		return successWithData(unlockService.lambdaQuery().eq(GMilestoneUnlock::getMilestoneId, milestoneId).list());
	}

	@ApiOperation(value = "里程碑删除", notes = "里程碑删除")
	@DeleteMapping("/deleteMilestone/{id}")
	public Result<?> deleteMilestone(@ApiParam(value = "里程碑id", required = true) @PathVariable Long id) {
		return service.deleteMilestone(id);
	}

	@ApiOperation(value = "根据里程碑id查询所有里程碑成本项Vo", notes = "根据里程碑id查询所有里程碑成本项Vo")
	@GetMapping("/readOnly/getAllMilestoneRequirementVoByMilestoneId/{milestoneId}")
	public Result<List<MilestoneRequirementVo>> getAllMilestoneRequirementVoByMilestoneId(@ApiParam(value = "里程碑id", required = true) @PathVariable Long milestoneId) {
		return successWithData(requirementService.getAllMilestoneRequirementVoByMilestoneId(milestoneId));
	}

	@ApiOperation(value = "根据里程碑id查询所有里程碑解锁项Vo", notes = "根据里程碑id查询所有里程碑解锁项Vo")
	@GetMapping("/readOnly/getAllMilestoneUnlockVoByMilestoneId/{milestoneId}")
	public Result<List<MilestoneUnlockVo>> getAllMilestoneUnlockVoByMilestoneId(@ApiParam(value = "里程碑id", required = true) @PathVariable Long milestoneId) {
		return successWithData(unlockService.getAllMilestoneUnlockVoByMilestoneId(milestoneId));
	}

}
